﻿<template>
  <a-modal
    title="新增会员其他信息"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="CRM_ID " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入CRM_ID " v-decorator="['crmId']" />
        </a-form-item>
        <a-form-item label="TIP_TYPE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入TIP_TYPE " v-decorator="['tipType']" />
        </a-form-item>
        <a-form-item label="TIP_LIMIT " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择TIP_LIMIT " v-decorator="['tipLimit']" @change="onChangetipLimit"/>
        </a-form-item>
        <a-form-item label="FIELD_01 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入FIELD_01 " v-decorator="['field01']" />
        </a-form-item>
        <a-form-item label="FIELD_02 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入FIELD_02 " v-decorator="['field02']" />
        </a-form-item>
        <a-form-item label="FIELD_03 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入FIELD_03 " v-decorator="['field03']" />
        </a-form-item>
        <a-form-item label="TIP_CODE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入TIP_CODE " v-decorator="['tipCode']" />
        </a-form-item>
        <a-form-item label="TIP_MESSAGE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入TIP_MESSAGE " v-decorator="['tipMessage']" />
        </a-form-item>
        <a-form-item label="卡号 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入卡号 " v-decorator="['icNo']" />
        </a-form-item>
        <a-form-item label="单位ID " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入单位ID " v-decorator="['companyId']" />
        </a-form-item>
        <a-form-item label="单位编码 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入单位编码 " v-decorator="['companyCode']" />
        </a-form-item>
        <a-form-item label="单位名称 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入单位名称 " v-decorator="['companyName']" />
        </a-form-item>
        <a-form-item label="01 个人发票 02 单位发票 00 不开票 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入01 个人发票 02 单位发票 00 不开票 " v-decorator="['invoiceType']" />
        </a-form-item>
        <a-form-item label=" 1 正常 0 删除 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 1 正常 0 删除 " v-decorator="['status']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    IcInfoExtendAdd
  } from '@/api/modular/main/IcInfoExtendManage'

  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        tipLimitDateString: '',
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            values.tipLimit = this.tipLimitDateString
            IcInfoExtendAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      onChangetipLimit(date, dateString) {
        this.tipLimitDateString = dateString
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
